<?php
namespace app\index\controller;
/*
 * content : 测试方法类
 * Author  : Songyicong 
 * time    : 2018-04-26 17:03:35 
 * email   : m13726262373@163.com 
 */
use think\Db;
use think\Env;

use app\api\extra\Rsa;
use app\api\extra\Utils;
use app\api\extra\Email;
use sycapi\wechat\Wechat;
use app\api\extra\Msgstr;


class Index{
    public function index(){
        // 网页获取用户信息操作
        // dump(Env::get('wechat_login_callback'));
        // 第一步 （获取到code）
        $oauth = Wechat::oauth();
        $user = $oauth->getOauthRedirect("http://localhost/rest_api_base/public/index.php/");
        //重定向到指定的URL地址 并且使用302
        // return $this->$require->redirect('http://thinkphp.cn/blog/2');
        return redirect($user);
        // echo "<a href='$user'>用户</a>";

        // // 第二步 通过code 换取 access_token 和 open_id
        // $oauth->getOauthAccessToken();

        // // 第三步 判断access_token 不过期的情况下获取用户信息
        // $oauth->getOauthUserInfo($access_token,$openid)


        // dump(self::getMoney2(155,150,0.1));

        // dump(Utils::getQrCode("http://www.baidu.com"));
        // dump(my_str_replace("1111",1,0));
        // dump(Email::verifyCode('291923058@qq.com',"4bNDrR"));
        // dump(Email::getCode('291923058@qq.com',6,3,6));
        // dump(\think\Cache::get("code_291923058@qq.com"));
    //    dump(Email::sendRegist('291923058@qq.com',1)); 
        // dump(Env::get('mail_charset'));
//          $html = <<<eot
//         <!DOCTYPE html>
// <html>
// <head>
//     <meta charset="utf-8" />
//     <meta http-equiv="X-UA-Compatible" content="IE=edge">
//     <title>Page Title</title>
//     <meta name="viewport" content="width=device-width, initial-scale=1">
//     <link rel="stylesheet" type="text/css" media="screen" href="main.css" />
//     <script src="main.js"></script>
// </head>
// <body>
//     <h1>你好，这是邮件系统！哈哈哈啊哈</h1>
//     <a href="http://www.52laoshiji.com">点击跳转到我的网站</a>
// </body>
// </html>
// eot;
//         dump(sendEmail([['user_email' => '291923058@qq.com', 'content' => $html]]));
        // header('Content-Type:text/html;Charset=utf-8;');

        // $string = isset($_GET['a']) ? $_GET['a'] : '测试123';

        // //证书路径
        // $pubfile = ROOT_PATH.'ssl/test.crt';
        // $prifile = ROOT_PATH.'ssl/test.pem';
        // //apache路径下的openssl.conf文件路径
        // $openssl_config_path = "D:/phpStudy/Apache/conf/openssl.cnf";

        // $rsa =new Rsa($pubfile,$prifile,$openssl_config_path);

        // echo "<pre>";
        // //生成签名
        // echo "\n签名的字符串:\n$string\n\n";
        // $sign = $rsa->sign($string);
        // echo "\n生成签名的值:\n$sign";

        // //验证签名
        // $p=$rsa->verify($string, $sign);
        // echo "\n验证签名的值:\n$p";


        // //加密
        // echo "\n\r加密的字符串:\n$string\n\n";
        // $x = $rsa->encrypt($string);
        // echo "\n生成加密的值:\n$x";

        //  //解密
        // $y = $rsa->decrypt($x);
        // echo "\n解密的值:\n$y";
        // echo "</pre>";

        // //创建新的密匙
        // echo "\n创建新的密匙:\n";
        // $rsa->buildNewKey();



        // $data['create_time'] = time();
        // $data['login_name'] = 'admin';
        // $data['user_name'] = '测试用户';
        // $data['ip'] = '127.0.0.1,'.get_client_ip();
        // $data['password'] = md5(md5('123456'.Env::get('seed_password')));
        // $data['secret'] = encrypt('admin_测试用户_'.$data['password'],Env::get('seed_password'));
        // $data['client_id'] = cardNum();
        // $data['status'] = 'rest_api';
        // $data['encry_type'] = '2';
        // $data['auth_num'] = '999999';
        // $data['sign'] = 'rest_api';

        // Db::table('km_admin')->insert($data);
        // $num = $this->think_encrypt("12345622111112121324121213213121123","shajkhdkjoi1237984121");
        // dump($num);
        // dump(strlen($num));
        // dump($this->think_decrypt($num,"shajkhdkjoi1237984121"));

        // $num1 = encrypt("12345622111112dsadasadsadasdsasfasfassdsasfasfassdsasfasfas121324121213213121123","shajkhdkjoi1237984121");
        // dump($num1);
        // dump(strlen($num1));
        // dump(decrypt($num1,"shajkhdkjoi1237984121"));
        // $access_token = Utils::getToken(Utils::getAppId('测试用户'),Utils::getSecret(md5(md5('123456'.Env::get('seed_password')))));
        // dump(Utils::getOpenId($access_token,1,100));
        // dump('_000000000000000000000000000000000000000000000000000000000000000000');
        // return 111;
    }

    function think_encrypt($data, $key = '', $expire = 0) {
        $key  = md5(empty($key) ? C('DATA_AUTH_KEY') : $key);
        $data = base64_encode($data);
        $x    = 0;
        $len  = strlen($data);
        $l    = strlen($key);
        $char = '';
        for ($i = 0; $i < $len; $i++) {
            if ($x == $l) $x = 0;
            $char .= substr($key, $x, 1);
            $x++;
        }
        $str = sprintf('%010d', $expire ? $expire + time():0);
        for ($i = 0; $i < $len; $i++) {
            $str .= chr(ord(substr($data, $i, 1)) + (ord(substr($char, $i, 1)))%256);
        }
        return str_replace(array('+','/','='),array('-','_',''),base64_encode($str));
    }
    /**
     * 系统解密方法
     * @param  string $data 要解密的字符串 （必须是think_encrypt方法加密的字符串）
     * @param  string $key  加密密钥
     * return string
     * @author 麦当苗儿 <zuojiazi@vip.qq.com>
     */
    function think_decrypt($data, $key = ''){
        $key    = md5(empty($key) ? C('DATA_AUTH_KEY') : $key);
        $data   = str_replace(array('-','_'),array('+','/'),$data);
        $mod4   = strlen($data) % 4;
        if ($mod4) {
           $data .= substr('====', $mod4);
        }
        $data   = base64_decode($data);
        $expire = substr($data,0,10);
        $data   = substr($data,10);
        if($expire > 0 && $expire < time()) {
            return '';
        }
        $x      = 0;
        $len    = strlen($data);
        $l      = strlen($key);
        $char   = $str = '';
        for ($i = 0; $i < $len; $i++) {
            if ($x == $l) $x = 0;
            $char .= substr($key, $x, 1);
            $x++;
        }
        for ($i = 0; $i < $len; $i++) {
            if (ord(substr($data, $i, 1))<ord(substr($char, $i, 1))) {
                $str .= chr((ord(substr($data, $i, 1)) + 256) - ord(substr($char, $i, 1)));
            }else{
                $str .= chr(ord(substr($data, $i, 1)) - ord(substr($char, $i, 1)));
            }
        }
        return base64_decode($str);
    }

    public static function getMoney($money,$year,$lixi){
        $max = 0;
        for($i=1;$i<=$year;$i++){
            $max = ($max+$money)*(1+$lixi);
        }
        return $max;
    }

    public static function getMoney2($money,$days,$lirun){
        $max = $money;
        for($i = 1;$i<=$days;$i++){
            $max = $max*$lirun+$max;
            echo "<span style='display: inline-block;width: 100%;font-size: 18px;'>第 $i 次,"."投资金额(usdt)：".   ($max+88) ."  ,约合人民币(元)：".$max*6.49."</span>";
            
            echo "<br><br>";
            if($i%15 == 0){
                echo "<hr>";
                echo "<br>";
            }
        }
        return $max;
    }
}
